﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WcfTest.AdministratorService;
using WcfTest.AuthorService;
using WcfTest.BackAuthorService;

namespace WcfTest
{
    public class Program
    {

        static string AdminiTk;

        static void Main(string[] args)
        {
            AdministratorServiceClient ac = new AdministratorServiceClient();
            ac.LoginCompleted += ac_LoginCompleted;
            ac.LoginAsync(new WcfTest.AdministratorService.LoginImport() { 
             Account="admin", Password="admin"
            });
            ConsoleKeyInfo key = Console.ReadKey();
            while (key.Key != ConsoleKey.Escape)
            {
                key = Console.ReadKey();
            }
        }

        static void Test()
        {
            AdministratorServiceClient ac = new AdministratorServiceClient();
            ac.GetAdministratorLandingRecordsCompleted += ac_GetAdministratorLandingRecordsCompleted;
            ac.GetAdministratorLandingRecordsAsync(new GetAdministratorLandingRecordsImport() { PageIndex = 1, Token = AdminiTk });

            BackAuthorService.AuthorServiceClient ss = new BackAuthorService.AuthorServiceClient();
            ss.GetUsersCompleted += ss_GetUsersCompleted;
            ss.GetUsersAsync(new BackAuthorService.GetUsersImport() { PageIndex = 1, Token = AdminiTk });


            ss.GetGoldsChangeRecordsCompleted += ss_GetGoldsChangeRecordsCompleted;
            ss.GetGoldsChangeRecordsAsync(new BackAuthorService.GetGoldsChangeRecordImport()
            {
                PageIndex = 1,
                Token = AdminiTk 
            });

            ss.GenerateRechargeCardCompleted += ss_GenerateRechargeCardCompleted;
            ss.GenerateRechargeCardAsync(new GenerateRechargeCardImport() {
                Golds = 10000,
                Token = AdminiTk
            });

        }

        static void ss_GenerateRechargeCardCompleted(object sender, BackAuthorService.GenerateRechargeCardCompletedEventArgs e)
        {

            if (e.Result.Success)
            {
                Console.WriteLine("充值卡:" + e.Result.Info.Account);
            }
            else
            {
                Console.WriteLine("生成充值卡失败:" + e.Result.Error);
            }
        }

        static void ss_GetGoldsChangeRecordsCompleted(object sender, BackAuthorService.GetGoldsChangeRecordsCompletedEventArgs e)
        {
            if (e.Result.Success)
            {
                Console.WriteLine("用户帐变记录数量:" + e.Result.CountOfAllMessage);
            }
            else
            {
                Console.WriteLine("获取用户帐变错误:" + e.Result.Error);
            }
        }

        static void ss_GetUsersCompleted(object sender, BackAuthorService.GetUsersCompletedEventArgs e)
        {
            if (e.Result.Success)
            {
                Console.WriteLine("用户记录数量:" + e.Result.CountOfAllMessage);
            }
            else
            {
                Console.WriteLine("获取用户列表错误:" + e.Result.Error);
            }
        }


      

        static void ac_LoginCompleted(object sender, AdministratorService.LoginCompletedEventArgs e)
        {
            if(e.Result.Success)
            {
                AdminiTk = e.Result.Info.Token;
                Test();
            }else
            {
                Console.WriteLine("登录错误" + e.Result.Error);
            }
        }


        static void ac_GetAdministratorLandingRecordsCompleted(object sender, GetAdministratorLandingRecordsCompletedEventArgs e)
        {
            if (e.Result.Success)
            {
                Console.WriteLine("登录记录数量:" + e.Result.CountOfAllMessage);   
            }
            else
            {
                Console.WriteLine("获取登录记录错误" + e.Result.Error);
            }
          
        }
    }
}
